package cn.com.dcsgo.controller;


import cn.com.dcsgo.model.sys.RegionWare;
import cn.com.dcsgo.result.Result;
import cn.com.dcsgo.service.RegionWareService;
import cn.com.dcsgo.vo.sys.RegionWareQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;

/*
前端接口查看前端文件：
uu-preferred-front-end/uuyx-admin/src/api/sys/regionWare.js
*/

/**
 * <p>
 * 城市仓库关联表 前端控制器
 * </p>
 *
 * @author Dcsgo
 * @since 2025-04-01
 */
@RestController
@Api(tags = "开通区域")
@RequiredArgsConstructor
@RequestMapping("admin/sys/regionWare")
public class RegionWareController {
    private final RegionWareService regionWareService;

    @ApiOperation("获取开通区域列表")
    @GetMapping("{page}/{size}")
    public Result<IPage<RegionWare>> getPageList(@PathVariable Long page,
                                                 @PathVariable Long size,
                                                 RegionWareQueryVo regionWare) {
        Page<RegionWare> pageParam = new Page<>(page, size);
        IPage<RegionWare> pageResult = regionWareService.selectRegionWarePage(pageParam, regionWare);
        return Result.ok(pageResult);
    }

    @ApiOperation("添加开通区域")
    @PostMapping("save")
    public Result<Serializable> saveRegionWare(@RequestBody RegionWare regionWare) {
        regionWareService.saveRegionWare(regionWare);
        return Result.ok(null);
    }

    @ApiOperation("删除开通区域")
    @DeleteMapping("remove/{id}")
    public Result<Serializable> removeRegionWare(@PathVariable Long id) {
        regionWareService.removeById(id);
        return Result.ok(null);
    }

    @ApiOperation("取消开通区域")
    @PostMapping("updateStatus/{id}/{status}")
    public Result<Serializable> updateStatus(@PathVariable Long id, @PathVariable Integer status) {
        RegionWare regionWare = new RegionWare();
        regionWare.setId(id);
        regionWare.setStatus(status);
        regionWareService.updateById(regionWare);
        return Result.ok(null);
    }
}

